<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
		<link rel="stylesheet" type="text/css" href="css/style.css"/>
		<title>管理员登录</title>
		<script src="js/jquery.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/jquery.validate.min.js"></script>
		<style type="text/css">
			label.error {
				color: orange;
			}
		</style>
	</head>
	<body>
		<div class="bg">
			<img src="images/7624.jpg"/>
		</div>
		<div class="container">
			<h1 class="lgzt"><span style="padding-right:100px;">摄</span><span>区</span></h1>
			<img id="logo" src="images/APP-logo.png" />
			<div class="middle text-center center-block vertical-center">
				<div class="jz vertical-center">
					<h1>登录</h1>
					<form class="form-horizontal" id="frm_login" onSubmit="return false">
							<div class="form-group a1">
									<input type="text" class="form-control" id="usnm" name="usnm" placeholder="请输入你的手机号">
								</div>
							<div class="form-group a2">
									<input type="password" class="form-control" id="pswd" name="pswd" placeholder="密码">
							</div>
							<div class="form-group">
									<button type="submit" class="btn btn-default">登录</button>
							</div>
						</form>
				</div>	
			</div>
		</div>
		<script src="js/fd_to_json.js"></script>
		<script>
			function tj() {
				var frm = document.getElementById("frm_login");
				formData = new FormData(frm);
				var json_Data = convert_FormData_to_json(formData);
				var xhr = new XMLHttpRequest;
				xhr.open("POST", "php/userlogin.php", true);
				xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
				xhr.send(json_Data);
				xhr.onreadystatechange = function() {
					if(xhr.readyState == 4) {
					//alert(xhr.responseText);
						var s = JSON.parse(xhr.responseText);
						alert(s.mes);
						if(s.code == 1) {
							localStorage.username = s.user;
							location.href = "admin.html";
						} else {
							$("#pswd").val("");
							$("#pswd").focus();
						}
					}
				}
			}
			$(function() {
				$("#frm_login").validate({
					submitHandler: function(form) {
						tj();
					},
					rules: {
						usnm: {
							required: true,
							minlength: 2
						},
						pswd: {
							required: true,
							minlength: 5
						}
					},
					messages: {
						usnm: {
							required: "请输入用户名",
							minlength: "用户名必需由两个字母组成"
						},
						pswd: {
							required: "请输入密码",
							minlength: "密码长度不能小于 5 个字母"
						}
					}
				})
			})
		</script>
	</body>
</html>
